#!/usr/bin/python3
# -*- coding: utf-8 -*-

import requests
import json
import re
import random
import threading

THREAD_CNT = 50
THREAD_LOOP_CNT = 5
MIN_CHALLENGE_ID=13
MAX_CHALLENGE_ID=300
MAX_CHALLENGE_PAGE=20
MAX_USER_ID=1600
DONATE_STEP_CNT=9000

JUST_LOGIN_COMMIT=True

# BASE_URL = "https://wechat.gdzyon.com"
BASE_URL = "https://wechatdev.gdzyon.com"
# 登录提交步数
LOGIN_COMMIT = "/user/pub/robot/loginAndCommit"
# 套装列表
ITEM_LIST = "/user/item/list"
# 挑战详情
CHALLENGE_DETAIL = "/task/challenge/detail"
# 自己相关的进行中的挑战
CHALLENGE_LIST = "/task/challenge/list"
# 其他挑战
OTHER_CHALLENGE_LIST = "/task/challenge/list/other"
# 一键领取奖励
AWARD_ALL = "/task/challenge/award/all"
# 我的成绩
ACHIEVEMENT = "/task/challenge/achievement"
# 年会捐步
DONATE_STEP = "/task/donate/step"
# 年会捐步数据
DONATE_DATA = "/user/pub/donate/data"
# 年会捐步数据
DONATE_DATA = "/user/pub/donate/data"
# 兑换步数
STEP_EXCHANGE = "/user/step/exchange"
# 红点：
REDPOINT = "/task/challenge/invite/redpoint"
# 已读
READ = "/task/challenge/invite/read"
# 受邀请列表
INVITE_LIST_OTHER = "/task/challenge/invite/list/other"
# 兑换套装
EXCHANGE = "/user/item/exchange"
# 切换形象
SELECT_AVATAR = "/user/item/avatar/select"
# 用户数据
USER_INFO = "/user/user/info"


encryptedData="X9Fh+CrGwiKjICF+bk1il3JSAYKSbGk/M2GPo1ZHLwdB1KciGMDhYUjWM062bVIUrsWhZ1mNQDCQw5ZY6j6U93hp14v2BG4YHz/NvnnfFfy/lmqdrtk29lr+whlnKKctBhvGthb2/f5tjqUklIqgog6/U5892F2HcRnnkXfq9vaDl6NIVuw5hbAxuA42TnMLmecw3xXVrhex70Z8mtA5NNrVucxitVTLBYbqsOa8rDHYETmAGBEoTjUA7/P3l483iC13wkUmjn2KdYugindnUWrPna8eQM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4S8YPxW9O70/xt0n7Aw+vzLHy7po7/0zZaz2ELcAxoo2Hpp+5gas1NGl8Dnwjqka1qDGqUqhfRvdunwy8csB23ipjcHTttF9++NT8XLLfTvpbcl2AlW42iczi3GaJeke79RDkbmfSkFaaAr4uM/M3BJnJjus23LjfPVX6hHll27R91Oa1CEJtQjG1IwJZ6sa8u2uZ+b2FbiQGsUh3YE7y0f6foYWaQpLQ/d8lbQ6f4Kp4rjex8nI6PBlvXNy3l+eP5PX4jB2iYoT7/Nj2wpXv4Oaa";
headers={'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}


def get(session, url, data):
    httpResp = session.post(url, data=data, headers=headers)
    print(json.loads(httpResp.text))

def main():
    session = requests.Session()
    for num in range(0, THREAD_LOOP_CNT):
        try:
            data = {
                "loginData": encryptedData,
                "stepData": encryptedData,
                "step": 20000
            }
            httpResp = session.post(BASE_URL + LOGIN_COMMIT, data=data, headers=headers)
            res = json.loads(httpResp.text)
            token = res['data']['accessToken']

            if token is not None:
                print("===================================================")
                print("login and commit step:")
                print(token)
                if JUST_LOGIN_COMMIT:
                    continue
                print("===================================================")
                print("item list:")
                data = {
                    "access_token": token,
                    "page": 0,
                    "size": 10
                }
                get(session, BASE_URL + ITEM_LIST, data)

                print("===================================================")
                print("challenge detail:")
                print("item list:")
                data = {
                    "access_token": token,
                    "challengeId": random.randint(MIN_CHALLENGE_ID, MAX_CHALLENGE_ID)
                }
                get(session, BASE_URL + CHALLENGE_DETAIL, data)

                print("===================================================")
                print("user challenge list:")
                data = {
                    "access_token": token,
                    "page": 0,
                    "size": 10
                }
                get(session, BASE_URL + CHALLENGE_LIST, data)

                print("===================================================")
                print("other challenge list:")
                data = {
                    "access_token": token,
                    "page": random.randint(0, MAX_CHALLENGE_PAGE),
                    "size": 10
                }
                get(session, BASE_URL + OTHER_CHALLENGE_LIST, data)
                print("===================================================")

                print("award all:")
                data = {
                    "access_token": token
                }
                get(session, BASE_URL + AWARD_ALL, data)
                print("===================================================")

                print("achievement:")
                data = {
                    "access_token": token,
                    "page": 0,
                    "size": 10
                }
                get(session, BASE_URL + ACHIEVEMENT, data)
                print("===================================================")

                print("achievement:")
                data = {
                    "access_token": token,
                    "page": 0,
                    "size": 10
                }
                get(session, BASE_URL + ACHIEVEMENT, data)
                print("===================================================")

                print("donate step:")
                data = {
                    "access_token": token,
                    "step": DONATE_STEP_CNT
                }
                get(session, BASE_URL + DONATE_STEP, data)
                print("===================================================")

                print("donate data:")
                data = {}
                get(session, BASE_URL + DONATE_DATA, data)
                print("===================================================")

                print("redpoint:")
                data = {
                    "access_token": token
                }
                get(session, BASE_URL + REDPOINT, data)
                print("===================================================")

                print("read:")
                data = {
                    "access_token": token,
                    "idList": str(random.randint(10,100)) + "," + str(random.randint(10,100)) + "," + str(random.randint(10,100)) + "," + str(random.randint(10,100))
                }
                get(session, BASE_URL + READ, data)
                print("===================================================")

                print("invite list other:")
                data = {
                    "access_token": token,
                    "page": random.randint(0, MAX_CHALLENGE_PAGE),
                    "size": 10
                }
                get(session, BASE_URL + INVITE_LIST_OTHER, data)
                print("===================================================")

                print("invite list other:")
                data = {
                    "access_token": token,
                    "page": random.randint(0, MAX_CHALLENGE_PAGE),
                    "size": 10
                }
                get(session, BASE_URL + INVITE_LIST_OTHER, data)
                print("===================================================")

                print("exchange item:")
                data = {
                    "access_token": token,
                    "itemId": 1
                }
                get(session, BASE_URL + EXCHANGE, data)
                print("===================================================")

                print("select avatar:")
                data = {
                    "access_token": token,
                    "singleId": 4
                }
                get(session, BASE_URL + SELECT_AVATAR, data)
                print("===================================================")

                print("user info:")
                data = {
                    "access_token": token,
                    "userId": random.randint(10, MAX_USER_ID)
                }
                get(session, BASE_URL + USER_INFO, data)
                print("===================================================")
        except Exception as e:
            print(e)
        finally:
            session.close()


class myThread (threading.Thread):
    def __init__(self, threadID):
        threading.Thread.__init__(self)
        self.threadID = threadID
    def run(self):
        print("启动线程：" + str(self.threadID))
        main()
        print("关闭线程：" + str(self.threadID))

if __name__ == '__main__':
    threads = []
    for num in range(0, THREAD_CNT):
        thread = myThread(num)
        thread.start()
        threads.append(thread)
    # 等待所有线程完成
    for t in threads:
        t.join()
    print ("退出主线程")
